package o;

import com.google.gson.JsonSyntaxException;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import java.io.IOException;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public final class aum implements ats {
    private final atw ˊ;
    private final aut ˋ = aut.ˎ();
    private final atd ˎ;
    private final atv ˏ;
    private final aud ॱ;

    static abstract class d {
        final boolean ʼ;
        final boolean ॱॱ;
        final String ᐝ;

        abstract boolean ˋ(Object obj) throws IOException, IllegalAccessException;

        abstract void ˎ(auy o_auy, Object obj) throws IOException, IllegalAccessException;

        abstract void ॱ(aux o_aux, Object obj) throws IOException, IllegalAccessException;

        protected d(String str, boolean z, boolean z2) {
            this.ᐝ = str;
            this.ʼ = z;
            this.ॱॱ = z2;
        }
    }

    public static final class c<T> extends ato<T> {
        private final Map<String, d> ˎ;
        private final aua<T> ॱ;

        c(aua<T> o_aua_T, Map<String, d> map) {
            this.ॱ = o_aua_T;
            this.ˎ = map;
        }

        public T ˏ(auy o_auy) throws IOException {
            if (o_auy.ʻ() == auz.NULL) {
                o_auy.ॱॱ();
                return null;
            }
            T ˋ = this.ॱ.ˋ();
            try {
                o_auy.ॱ();
                while (o_auy.ˋ()) {
                    d dVar = (d) this.ˎ.get(o_auy.ᐝ());
                    if (dVar == null || !dVar.ॱॱ) {
                        o_auy.ˋॱ();
                    } else {
                        dVar.ˎ(o_auy, ˋ);
                    }
                }
                o_auy.ˏ();
                return ˋ;
            } catch (Throwable e) {
                throw new JsonSyntaxException(e);
            } catch (IllegalAccessException e2) {
                throw new AssertionError(e2);
            }
        }

        public void ˎ(aux o_aux, T t) throws IOException {
            if (t == null) {
                o_aux.ᐝ();
                return;
            }
            o_aux.ˊ();
            try {
                for (d dVar : this.ˎ.values()) {
                    if (dVar.ˋ(t)) {
                        o_aux.ॱ(dVar.ᐝ);
                        dVar.ॱ(o_aux, t);
                    }
                }
                o_aux.ˏ();
            } catch (IllegalAccessException e) {
                throw new AssertionError(e);
            }
        }
    }

    public aum(atv o_atv, atd o_atd, atw o_atw, aud o_aud) {
        this.ˏ = o_atv;
        this.ˎ = o_atd;
        this.ˊ = o_atw;
        this.ॱ = o_aud;
    }

    public boolean ˊ(Field field, boolean z) {
        return ˏ(field, z, this.ˊ);
    }

    static boolean ˏ(Field field, boolean z, atw o_atw) {
        return (o_atw.ˊ(field.getType(), z) || o_atw.ˋ(field, z)) ? false : true;
    }

    private List<String> ˊ(Field field) {
        SerializedName serializedName = (SerializedName) field.getAnnotation(SerializedName.class);
        if (serializedName == null) {
            return Collections.singletonList(this.ˎ.ˋ(field));
        }
        String value = serializedName.value();
        String[] alternate = serializedName.alternate();
        if (alternate.length == 0) {
            return Collections.singletonList(value);
        }
        List<String> arrayList = new ArrayList(alternate.length + 1);
        arrayList.add(value);
        for (Object add : alternate) {
            arrayList.add(add);
        }
        return arrayList;
    }

    public <T> ato<T> ˎ(atb o_atb, auv<T> o_auv_T) {
        Class ˋ = o_auv_T.ˋ();
        if (Object.class.isAssignableFrom(ˋ)) {
            return new c(this.ˏ.ˎ((auv) o_auv_T), ˋ(o_atb, o_auv_T, ˋ));
        }
        return null;
    }

    private d ˎ(atb o_atb, Field field, String str, auv<?> o_auv_, boolean z, boolean z2) {
        final boolean ˊ = aub.ˊ(o_auv_.ˋ());
        JsonAdapter jsonAdapter = (JsonAdapter) field.getAnnotation(JsonAdapter.class);
        ato o_ato = null;
        if (jsonAdapter != null) {
            o_ato = this.ॱ.ˏ(this.ˏ, o_atb, o_auv_, jsonAdapter);
        }
        final boolean z3 = o_ato != null;
        if (o_ato == null) {
            o_ato = o_atb.ˏ(o_auv_);
        }
        final Field field2 = field;
        final atb o_atb2 = o_atb;
        final auv<?> o_auv_2 = o_auv_;
        return new d(this, str, z, z2) {
            final /* synthetic */ aum ʽ;

            void ॱ(aux o_aux, Object obj) throws IOException, IllegalAccessException {
                ato o_ato;
                Object obj2 = field2.get(obj);
                if (z3) {
                    o_ato = o_ato;
                } else {
                    o_ato = new auo(o_atb2, o_ato, o_auv_2.ˏ());
                }
                o_ato.ˎ(o_aux, obj2);
            }

            void ˎ(auy o_auy, Object obj) throws IOException, IllegalAccessException {
                Object ˏ = o_ato.ˏ(o_auy);
                if (ˏ != null || !ˊ) {
                    field2.set(obj, ˏ);
                }
            }

            public boolean ˋ(Object obj) throws IOException, IllegalAccessException {
                if (this.ʼ && field2.get(obj) != obj) {
                    return true;
                }
                return false;
            }
        };
    }

    private Map<String, d> ˋ(atb o_atb, auv<?> o_auv_, Class<?> cls) {
        Map<String, d> linkedHashMap = new LinkedHashMap();
        if (cls.isInterface()) {
            return linkedHashMap;
        }
        Type ˏ = o_auv_.ˏ();
        while (cls != Object.class) {
            for (AccessibleObject accessibleObject : cls.getDeclaredFields()) {
                boolean ˊ = ˊ(accessibleObject, true);
                boolean ˊ2 = ˊ(accessibleObject, false);
                if (ˊ || ˊ2) {
                    this.ˋ.ˏ(accessibleObject);
                    Type ˊ3 = atp.ˊ(o_auv_.ˏ(), (Class) cls, accessibleObject.getGenericType());
                    List ˊ4 = ˊ(accessibleObject);
                    d dVar = null;
                    int size = ˊ4.size();
                    int i = 0;
                    while (i < size) {
                        String str = (String) ˊ4.get(i);
                        if (i != 0) {
                            ˊ = false;
                        }
                        d dVar2 = (d) linkedHashMap.put(str, ˎ(o_atb, accessibleObject, str, auv.ˋ(ˊ3), ˊ, ˊ2));
                        if (dVar != null) {
                            dVar2 = dVar;
                        }
                        i++;
                        dVar = dVar2;
                    }
                    if (dVar != null) {
                        throw new IllegalArgumentException(ˏ + " declares multiple JSON fields named " + dVar.ᐝ);
                    }
                }
            }
            o_auv_ = auv.ˋ(atp.ˊ(o_auv_.ˏ(), (Class) cls, cls.getGenericSuperclass()));
            cls = o_auv_.ˋ();
        }
        return linkedHashMap;
    }
}
